<template>
  <div class="login">
    <van-nav-bar
    title="修改密码"
    left-arrow
    @click-left="onClickLeft"
    />
    <van-form @submit="onSubmit">
      <van-field
        v-model="password"
        type="password"
        name="password"
        label="旧密码"
        placeholder="旧密码"
        :rules="regular.password"
      />
      <van-field
        v-model="password2"
        type="password"
        name="password2"
        label="新密码"
        placeholder="新密码"
        :rules="regular.password"
      />
      <div class="dz">
        <router-link to="/login">登录</router-link>
      </div>
      <div style="margin: 16px;">
        <van-button round block type="info" native-type="submit">登录</van-button>
      </div>
    </van-form>
  </div>
</template>

<script>
import { Form } from 'vant';
import { Field } from 'vant';
import regular from '@/utils/verify/regular'
export default {
  name: "WorkspaceJsonLogin",
  components:{
    [Form.name]:Form,
    [Field.name]:Field,
  },
  data() {
    return {
      regular,
      password:'',
      password2:'',
    };
  },

  methods: {
    onClickLeft(){
        this.$router.go(-1)
    },
    // 修改密码
    onSubmit() {
      let {password,password2}=this;
      this.uid=localStorage.getItem('uid')
      this.$http.post('/user/updatePwd',{
        oldPassword:password,
        newPassword:password2,
        uid:this.uid
      })
      .then(res=>{
        console.log(res);
        this.$toast(res.msg)
        localStorage.setItem('token','')
        setTimeout(()=>{
          this.$router.go(-1)
        },500)
      })
    },
    
  },
  mounted() {}

};
</script>

<style lang="scss" scoped>
.dz{
  padding: 2.66667vw 3.66667vw;
  span{
    display: inline-block;
    margin-left: 61.6vw;
  }
}
</style>